// pages/ChargebackReason/index.js
import api from '../../request/api.js'
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    model:{
      value: 3,
      evaluation: ''
    },
    reason:[],
    checkedReason:'',
    order_id:'',
    is_show : false,
  },
  radioChange(e) {
    let show;
    if(e.detail.value == '其它原因') {
      show = true;
    }else{
      show = false;
    }
    this.setData({
      checkedReason: e.detail.value,
      is_show : show
    })
  },
  async bindFormSubmit(e){
    console.dir(this.data.items)
    console.dir(e)
    const { order_id, checkedReason} = this.data
    const { evaluation } = e.detail.value
    const { data: res } = await api('POST', 'Recycle/order/cancelOrder', {
      order_id,
      reason: checkedReason,
      detailed: evaluation
    })
    if(res.code===200){
      wx.navigateTo({
        url: '../order/index',
      })
    }else{
      Toast(res.msg)
    }
  },
  async getReason (){
    const { data: res } = await api('GET', 'Recycle/other/cancelReasons')
    if(res.code===200){
      this.setData({
        reason: res.data
      })
    }
  },
  async postReason(){
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getReason()
    this.setData({
      order_id:options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})